package com.yidu.hbatsams.service.TrainingPlan.zxr;


import com.github.pagehelper.PageHelper;
import com.yidu.hbatsams.dao.AtsPlanCurriculumMapper;
import com.yidu.hbatsams.domain.AtsPlanCurriculum;
import com.yidu.hbatsams.domain.vo.UserVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author 朱星润
 * @类的描述——课计划Service
 * @date 2019/10/30下午 02:19
 */
@Service
public class AtsCurriculumServiceImpl implements AtsCurriculumService {
    @Resource
    AtsPlanCurriculumMapper atsPlanCurriculumMapper;//课计划Mapper

    /**
     * 查询课计划
     * @param request 请求
     * @param atsCurriculum 课计划对象
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<AtsPlanCurriculum> findAll(HttpServletRequest request, AtsPlanCurriculum atsCurriculum, Integer pageNum, Integer pageSize) {
        //获取当前登录人传进atsCurriculum对象
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //角色编码
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        atsCurriculum.setFilId(manager.getClerkId());
        //角色职业
        atsCurriculum.setName(manager.getUserName());
        //分页插件
        PageHelper.startPage(pageNum,pageSize);
        //AtsPlanCurriculum集合
        List<AtsPlanCurriculum> list=null;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练员
                list=atsPlanCurriculumMapper.findCoach(atsCurriculum);
               //4为运动员
            } else if ("4".equals(atsCurriculum.getType())){
                //查运动员
                list=atsPlanCurriculumMapper.findAthlete(atsCurriculum);
            } else {
                //查所有
                list=atsPlanCurriculumMapper.findAll(atsCurriculum);
            }
        } else {
            //查所有
            list=atsPlanCurriculumMapper.findAll(atsCurriculum);
        }


        return list;
    }
    /**
     * 查询课计划总行数
     *
     * @param request 请求
     * @param atsCurriculum 课计划对象
     * @return
     */
    @Override
    public int count(HttpServletRequest request, AtsPlanCurriculum atsCurriculum) {
        //获取当前登录人传进atsCurriculum对象
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //角色编码
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        atsCurriculum.setFilId(manager.getClerkId());
        //角色职业
        atsCurriculum.setName(manager.getUserName());
        //总行数
        int count=0;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练员
                count=atsPlanCurriculumMapper.countCoach(atsCurriculum);
                //4为运动员
            } else if ("4".equals(atsCurriculum.getType())){
                //查运动员
                count=atsPlanCurriculumMapper.countAthlete(atsCurriculum);
            } else {
                //查所有
                count=atsPlanCurriculumMapper.countCurAll(atsCurriculum);
            }
        } else {
            //查所有
            count=atsPlanCurriculumMapper.countCurAll(atsCurriculum);
        }
        return count;//查总行数
    }

    @Override
    public List<AtsPlanCurriculum> weekEchar(HttpServletRequest request, Map<String, Object> map) {
        //获取当前登录人信息
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //new课计划对象
        AtsPlanCurriculum atsCurriculum=new AtsPlanCurriculum();
        //角色编码传入对象
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        map.put("filId", manager.getClerkId());
        //角色职业
        map.put("name", manager.getUserName());
        //AtsPlanCurriculum集合
        List<AtsPlanCurriculum> list=null;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练
                list=atsPlanCurriculumMapper.weekEcharCoach(map);
                //4为运动员
            } else if ("4".equals(atsCurriculum.getType())) {
                //查运动员
                list=atsPlanCurriculumMapper.weekEcharAthlete(map);
            } else {
                //查所有
                list=atsPlanCurriculumMapper.weekEcharAll(map);

            }
        } else {
            //查所有
            list=atsPlanCurriculumMapper.weekEcharAll(map);
        }
        //查周计划统计图
        return list;
    }

    /**
     * 课计划统计图
     * @param request 请求
     * @param map 传入map集合
     * @return map集合
     */
    @Override
    public List<AtsPlanCurriculum> curEchar(HttpServletRequest request, Map<String, Object> map) {
        //获取当前登录人信息
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //new课计划对象
        AtsPlanCurriculum atsCurriculum=new AtsPlanCurriculum();
        //角色编码传入对象
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        map.put("filId", manager.getClerkId());
        //角色职业
        map.put("name", manager.getUserName());
        //AtsPlanCurriculum集合
        List<AtsPlanCurriculum> list=null;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练
                list=atsPlanCurriculumMapper.curEcharCoach(map);
                //4为运动员
            } else if ("4".equals(atsCurriculum.getType())) {
                //查运动员
                list=atsPlanCurriculumMapper.curEcharAthlete(map);
            } else {
                //查所有
                list=atsPlanCurriculumMapper.curEcharAll(map);
            }
        } else {
            //查所有
            list=atsPlanCurriculumMapper.curEcharAll(map);
        }
        return list;//查课计划统计图
    }

    /**
     * 统计图多选框
     *
     * @param request 请求
     * @param atsCurriculum 课计划
     * @return List集合
     */
    @Override
    public List<AtsPlanCurriculum> comboBox(HttpServletRequest request, AtsPlanCurriculum atsCurriculum) {
        //获取当前登录人传进atsCurriculum对象
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //角色编码
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        atsCurriculum.setFilId(manager.getClerkId());
        //角色职业
        atsCurriculum.setName(manager.getUserName());
        //AtsPlanCurriculum集合
        List<AtsPlanCurriculum> list=null;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练员
                list=atsPlanCurriculumMapper.findCoach(atsCurriculum);
                //4为运动员
            } else if ("4".equals(atsCurriculum.getType())){
                //查运动员
                list=atsPlanCurriculumMapper.findAthlete(atsCurriculum);
            } else {
                //查所有
                list=atsPlanCurriculumMapper.findAll(atsCurriculum);
            }
        } else {
            //查所有
            list=atsPlanCurriculumMapper.findAll(atsCurriculum);
        }


        return list;
    }


    /**
     * 根据主键查询
     *
     * @param curriculumId 课计划Id
     * @return AtsPlanCurriculum对象
     */
    @Override
    public AtsPlanCurriculum findById(Integer curriculumId) {
        //课计划Id查询
        return atsPlanCurriculumMapper.findById(curriculumId);
    }


    /**
     * 外键查询
     * @param weekId 周计划Id
     * @return AtsPlanCurriculum对象
     */
    @Override
    public List<AtsPlanCurriculum> findByWeekId(Integer weekId) {
        //周计划Id查询
        return atsPlanCurriculumMapper.findByWeekId(weekId);
    }
    /**
     * 课总时间统计图
     * @param request
     * @param map
     * @return
     */
    @Override
    public List<AtsPlanCurriculum> curPie(HttpServletRequest request, Map<String, Object> map) {
        //获取当前登录人信息
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //new课计划对象
        AtsPlanCurriculum atsCurriculum=new AtsPlanCurriculum();
        //角色编码传入对象
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        map.put("filId", manager.getClerkId());
        //角色职业
        map.put("name", manager.getUserName());
        //AtsPlanCurriculum集合
        List<AtsPlanCurriculum> list=null;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练
                list=atsPlanCurriculumMapper.curCoachPie(map);
                //4为运动员
            } else if ("4".equals(atsCurriculum.getType())) {
                //查运动员
                list=atsPlanCurriculumMapper.curAthletePie(map);
            } else {
                //查所有
                list=atsPlanCurriculumMapper.curAllPie(map);
            }
        } else {
            //查所有
            list=atsPlanCurriculumMapper.curAllPie(map);
        }


        return list;
    }


    /**
     * 课总时间统计图
     * @param request
     * @param map
     * @return
     */
    @Override
    public List<AtsPlanCurriculum> curAll(HttpServletRequest request, Map<String, Object> map) {
        //获取当前登录人信息
        UserVo manager = (UserVo) request.getSession().getAttribute("user");
        //new课计划对象
        AtsPlanCurriculum atsCurriculum=new AtsPlanCurriculum();
        //角色编码传入对象
        atsCurriculum.setType(manager.getCompanyId());
        //角色外键
        map.put("filId", manager.getClerkId());
        //角色职业
        map.put("name", manager.getUserName());
        //AtsPlanCurriculum集合
        List<AtsPlanCurriculum> list=null;
        //如果角色编码不为空则进入
        if(atsCurriculum.getType()!=null && !"".equals(atsCurriculum.getType())){
            //2，5为教练
            if ("2".equals(atsCurriculum.getType()) || "5".equals(atsCurriculum.getType())) {
                //查询教练
                list=atsPlanCurriculumMapper.curEcharCoach(map);
                //4为运动员
            } else if ("4".equals(atsCurriculum.getType())) {
                //查运动员
                list=atsPlanCurriculumMapper.curEcharAthlete(map);
            } else {
                //查所有
                list=atsPlanCurriculumMapper.curEcharAll(map);
            }
        } else {
            //查所有
            list=atsPlanCurriculumMapper.curEcharAll(map);
        }


        return list;
    }

}
